package com.uwlaser.modules.system.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.modules.system.domain.SysExternalSocketLog;
import com.uwlaser.modules.system.service.SysExternalSocketLogService;
import com.uwlaser.modules.system.service.dto.SysExternalSocketLogDto;
import com.uwlaser.modules.system.service.dto.SysExternalSocketLogQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author QZK
* @date 2022-12-06
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "Socket请求日志管理")
@RequestMapping("/api/sysExternalSocketLog")
public class SysExternalSocketLogController {

    private final SysExternalSocketLogService sysExternalSocketLogService;

    @GetMapping
    @Log("查询Socket请求日志")
    @ApiOperation("查询Socket请求日志")
    @PreAuthorize("@el.check('sysExternalSocketLog:list')")
    public ResponseEntity query(SysExternalSocketLogQueryParam query, Pageable pageable){
        return new ResponseEntity<>(sysExternalSocketLogService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增Socket请求日志")
    @ApiOperation("新增Socket请求日志")
    @PreAuthorize("@el.check('sysExternalSocketLog:add')")
    public ResponseEntity create(@Validated @RequestBody SysExternalSocketLogDto resources){
        return new ResponseEntity<>(sysExternalSocketLogService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改Socket请求日志")
    @ApiOperation("修改Socket请求日志")
    @PreAuthorize("@el.check('sysExternalSocketLog:edit')")
    public ResponseEntity update(@Validated @RequestBody SysExternalSocketLogDto resources){
        sysExternalSocketLogService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除Socket请求日志")
    @ApiOperation("删除Socket请求日志")
    @PreAuthorize("@el.check('sysExternalSocketLog:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        sysExternalSocketLogService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping("/reuploadOne")
    @Log("Socket请求单条重传")
    @ApiOperation("Socket请求单条重传")
    @PreAuthorize("@el.check('sysExternalSocketLog:edit')")
    public ResponseEntity reuploadOne(@RequestBody SysExternalSocketLog resources) throws Exception {
        sysExternalSocketLogService.reuploadOne(resources);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/reuploadAll")
    @Log("Socket请求一键重传")
    @ApiOperation("Socket请求一键重传")
    @PreAuthorize("@el.check('sysExternalSocketLog:edit')")
    public ResponseEntity reuploadAll(){
        sysExternalSocketLogService.reuploadAll();
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出Socket请求日志")
    @ApiOperation("导出Socket请求日志")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sysExternalSocketLog:list')")
    public void download(HttpServletResponse response, SysExternalSocketLogQueryParam query) throws IOException {
        sysExternalSocketLogService.download(sysExternalSocketLogService.queryAll(query), response);
    }*/

}
